//
//  YDEditInformationTopView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDEditInformationTopView.h"
#import "UIImageView+WebCache.h"
#import "YDBankCardModel.h"

@interface YDEditInformationTopView()

//背景图片
@property (nonatomic , weak) UIView *bankBack;
//银行图片
@property (nonatomic , weak) UIImageView *bankImage;
//银行名称
@property (nonatomic , weak) UILabel *bankName;
//账号
@property (nonatomic , weak) UILabel *bankAccount;
//持卡人
@property (nonatomic , weak) UILabel *cradMan;
//姓名
@property (nonatomic , weak) UILabel *cradManName;
//预留手机
@property (nonatomic , weak) UILabel *cradPhone;
//手机号码
@property (nonatomic , weak) UILabel *cradPhoneNumber;


@end


@implementation YDEditInformationTopView

-(void)setModel:(YDBankCardModel *)model
{
    _model = model;
    //卡图片
    [self.bankImage sd_setImageWithURL:[NSURL URLWithString:model.bankIconLink] placeholderImage:[UIImage imageNamed:@"bankcopy"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (image == nil) {
            self.bankImage.backgroundColor = [UIColor colorWithHexString:blueyGrey];
        }else
        {
            self.bankImage.backgroundColor = [UIImage mostColor:image];
        }
    }];
    //账号
    self.bankAccount.text = model.fourStarFormatterBankCard;
    //持卡人姓名
    self.cradManName.text = model.name;
    //手机号
    self.cradPhoneNumber.text = [NSString phoneNumberFormate:model.phone];
    //名称及支行信息
    if (model.branchName) {
        self.bankName.text = [NSString stringWithFormat:@"%@-%@" , model.name , model.branchName];
    }else{
       self.bankName.text = model.name;
    }
    
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self bankBack];
        [self bankImage];
        [self bankName];
        [self bankAccount];
        
        [self cradMan];
        [self cradManName];
        
        [self cradPhone];
        [self cradPhoneNumber];
        
    }
    return self;
}

+(instancetype)editInformationTopViewWithBankCardModel:(YDBankCardModel *)model
{
    YDEditInformationTopView *topView = [[self alloc] init];
    topView.model = model;
    return topView;
}

-(UIView *)bankBack
{
    if (_bankBack == nil) {
        UIView *bankBack = [[UIView alloc] init];
        [self addSubview:bankBack];
        bankBack.backgroundColor = NumberColor(66, 119, 232);
        bankBack.userInteractionEnabled = YES;
        [bankBack mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(18));
            make.right.equalTo(self).offset(-rate375(18));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(10));
                make.height.equalTo(@(rateX812(120)));
            }else{
                make.top.equalTo(self).offset(rate750(10));
                make.height.equalTo(@(rate750(120)));
            }
        }];
        bankBack.layer.cornerRadius = 5.0;
        bankBack.layer.masksToBounds = YES;
        
        _bankBack = bankBack;
    }
    return _bankBack;
}

-(UIImageView *)bankImage
{
    if (_bankImage == nil) {
        UIImageView *bankImage = [[UIImageView alloc] init];
        [self addSubview:bankImage];
        bankImage.image = [UIImage imageWithColor:[UIColor redColor]];
        bankImage.userInteractionEnabled = YES;
        [bankImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bankBack);
            make.left.equalTo(self.bankBack.mas_left).offset(rate375(16));
            make.height.width.equalTo(@(rate375(60)));
        }];
        bankImage.layer.cornerRadius = rate375(60) * 0.5;
        bankImage.layer.masksToBounds = YES;
        _bankImage = bankImage;
    }
    return _bankImage;
}
//银行名称
-(UILabel *)bankName
{
    if (_bankName == nil) {
        UILabel *bankName = [[UILabel alloc] init];
        [self addSubview:bankName];
        bankName.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        bankName.textColor = [UIColor whiteColor];
        bankName.textAlignment = NSTextAlignmentLeft;
        bankName.text = @"中国建设银行-支行信息";
        [bankName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bankImage.mas_right).offset(rate375(8));
            make.bottom.equalTo(self.bankImage.mas_centerY).offset(-rate750(5));
            make.right.equalTo(self.bankBack.mas_right).offset(-rate375(5));
        }];
        bankName.adjustsFontSizeToFitWidth = YES;
        _bankName = bankName;
    }
    return _bankName;
}

//银行账号
-(UILabel *)bankAccount
{
    if (_bankAccount == nil) {
        UILabel *bankAccount = [[UILabel alloc] init];
        [self addSubview:bankAccount];
        bankAccount.font = [UIFont boldSystemFontOfSize:font20ScreenWRate * LKScreenW];
        bankAccount.textColor = [UIColor whiteColor];
        bankAccount.textAlignment = NSTextAlignmentLeft;
        bankAccount.text = @"1234 5678 1234 5678 123";
        [bankAccount mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bankImage.mas_right).offset(rate375(8));
            make.top.equalTo(self.bankImage.mas_centerY).offset(rate750(1));
            make.right.equalTo(self.bankBack.mas_right).offset(-rate375(5));
        }];
        bankAccount.adjustsFontSizeToFitWidth = YES;
        _bankAccount = bankAccount;
    }
    return _bankAccount;
}

-(UILabel *)cradMan
{
    if (_cradMan == nil) {
        UILabel *cradMan = [[UILabel alloc] init];
        [self addSubview:cradMan];
        cradMan.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradMan.textColor = NumberColor(104, 114, 132);
        cradMan.textAlignment = NSTextAlignmentLeft;//104 114 132
        cradMan.text = @"持卡人";
        [cradMan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bankBack);
            make.right.equalTo(self.mas_left).offset(rate375(90));
            if (isPhoneX) {
                make.top.equalTo(self.bankBack.mas_bottom).offset(rateX812(10));
            }else{
                make.top.equalTo(self.bankBack.mas_bottom).offset(rate750(10));
            }
        }];
        cradMan.adjustsFontSizeToFitWidth = YES;
        _cradMan = cradMan;
    }
    return _cradMan;
}
-(UILabel *)cradManName
{
    if (_cradManName == nil) {
        UILabel *cradManName = [[UILabel alloc] init];
        [self addSubview:cradManName];
        cradManName.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradManName.textColor = [UIColor colorWithHexString:dark];
        cradManName.textAlignment = NSTextAlignmentLeft;//104 114 132
        cradManName.text = @"张三";
        [cradManName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cradMan.mas_right);
            make.centerY.equalTo(self.cradMan);
        }];
        _cradManName = cradManName;
    }
    return _cradManName;
}

-(UILabel *)cradPhone
{
    if (_cradPhone == nil) {
        UILabel *cradPhone = [[UILabel alloc] init];
        [self addSubview:cradPhone];
        cradPhone.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradPhone.textColor = NumberColor(104, 114, 132);
        cradPhone.textAlignment = NSTextAlignmentLeft;//104 114 132
        cradPhone.text = @"预留手机";
        [cradPhone mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.cradMan);
            if (isPhoneX) {
                make.top.equalTo(self.cradMan.mas_bottom).offset(rateX812(6));
            }else{
                make.top.equalTo(self.cradMan.mas_bottom).offset(rate750(6));
            }
        }];
        cradPhone.adjustsFontSizeToFitWidth = YES;
        _cradPhone = cradPhone;
    }
    return _cradPhone;
}

-(UILabel *)cradPhoneNumber
{
    if (_cradPhoneNumber == nil) {
        UILabel *cradPhoneNumber = [[UILabel alloc] init];
        [self addSubview:cradPhoneNumber];
        cradPhoneNumber.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradPhoneNumber.textColor = [UIColor colorWithHexString:dark];
        cradPhoneNumber.textAlignment = NSTextAlignmentLeft;//104 114 132
        cradPhoneNumber.text = @"13838383838";
        [cradPhoneNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cradPhone.mas_right);
            make.centerY.equalTo(self.cradPhone);
        }];
        _cradPhoneNumber = cradPhoneNumber;
    }
    return _cradPhoneNumber;
}


@end
